package com.example.myapplication;

import android.app.Application;
import android.content.SharedPreferences;
import android.util.TypedValue;

import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import com.example.myapplication.view.PullRefreshViewHelper;


public class MyApp extends Application {
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;

    private static MyApp instance = null;

    public static MyApp get() {

        return instance;

    }

    public SharedPreferences getSharedPreferences() {
        return sharedPreferences;
    }

    public void setSharedPreferences(SharedPreferences sharedPreferences) {
        this.sharedPreferences = sharedPreferences;
    }

    public SharedPreferences.Editor getEditor() {
        return editor;
    }

    public void setEditor(SharedPreferences.Editor editor) {
        this.editor = editor;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        PullRefreshViewHelper.get().init(14);
        PullRefreshViewHelper.get().setColors(getColors(R.color.purple_700), getColors(R.color.teal_700));
        PullRefreshViewHelper.get().setLoadStyle(PullRefreshViewHelper.LOAD_STYLE_CIRCLE);
        PullRefreshViewHelper.get().setLoadColor(getColors(R.color.teal_700));
        PullRefreshViewHelper.get().setLoadText("加载中...");
        PullRefreshViewHelper.get().setEmptyImage(R.mipmap.ic_pull_refresh);
        PullRefreshViewHelper.get().setEmptyColor(getColors(R.color.teal_700));
        PullRefreshViewHelper.get().setEmptyText("暂无数据~");
        PullRefreshViewHelper.get().setErrorImage(R.mipmap.ic_pull_refresh);
        PullRefreshViewHelper.get().setErrorColor(getColors(R.color.teal_700));
        PullRefreshViewHelper.get().setErrorText("加载失败了~");
        //SP数据存储相关代码
        sharedPreferences =getSharedPreferences("test",MODE_PRIVATE);
        editor =sharedPreferences.edit();

        //百度地图
        SDKInitializer.initialize(this);
        SDKInitializer.setCoordType(CoordType.BD09LL);

    }




    public int getColors(int id) {

        return getResources().getColor(id);

    }
    public int getWidth() {
        return getResources().getDisplayMetrics().widthPixels;
    }

    public int getHeight() {
        return getResources().getDisplayMetrics().heightPixels;
    }

    public int dp2Sp(int dp) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dp, getResources().getDisplayMetrics());
    }

    public int dp2Px(int dp) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
    }


}
